import React, { Component } from 'react'
import * as action from "../action/index.js"
import {connect} from "react-redux"  // 1.
import {bindActionCreators} from "redux" // 用来合并抽离出去的dispatch的
 class App extends Component {
   componentDidMount(){
     this.props.getList()
   }
   state = {
     name:"wangwrwam"
   }
  checkName(){
      this.props.setName(this.state.name)
  }
  render() {
     console.log(this.props)
    return (
      <div>{this.props.deomoReducer.name1}
      
        <button onClick={this.checkName.bind(this)}>点击我修改名字</button>
      </div>
    )
  }
}
// 将state注入到组件中去
let mapStateToProps = (state)=>{
    console.log(state,"state")
     return {
         ...state,
         
     }
}
// 将dispath注入到组件中去
// let mapDisPatchToProps = (dispatch)=>{
//       return {
//            // 在这个对象中我们写dispath 
//            setName(data){
//               dispatch({
//                 type:"setName",
//                 payload:data,
//               })
//            }
//       }
// }
// 将抽离出得dispatch 引入到组件中
let mapDisPatchToProps =(dispatch)=>bindActionCreators(action,dispatch)
let aaa = connect(mapStateToProps,mapDisPatchToProps)(App)

export default aaa //2.